$if not set mapping $set mapping tiny
$goto %mapping%

$label tiny

set cc /
	agri	Water-using agriculture
	prim	Forestry-fishing-mining and non-water agric
	food	Processed food
	othm	Other manufactures
	trad	Trade       
	trns	Transport   
	serv	Services /;

set ii /
	agri	Water-using agriculture
	prim	Forestry-fishing-mining and non-water agric
	food	Processed food
	othm	Other manufactures
	trad	Trade       
	trns	Transport   
	serv	Services /;

set rr /	NSW1	NorthernNSW ,    
		NSW2	NorthWestNSW,    
		NSW3	MrmbidgeeNSW,    
		NSW4	MurrayNSW   ,    
		NSW5	FarWestNSW  ,    
		NSW0	RoNSW       
		VIC1	MalleeVIC   ,    
		VIC2	LoddonCmpVIC,    
		VIC3	GoulbournVIC,    
		VIC4	OvensMrryVIC,    
		VIC0	RoVIC       ,    
		QLD1	DarlDownsQLD
		QLD2	SouthWestQLD,    
		QLD0	RoQLD       ,    
		SA1	MurrayLndsSA,    
		SA0	Other South Australia,    
		WA	Wester Australia,    
		TAS	Tasmania
		NT	Northern Territory,    
		ACT     Australian Capital Territory/;    

$goto readdata


$label water

set cc /
	shep	Sheep       
	othb	OthBroadAcre
	bctl	BeefCattle  
	dctl	DairyCattle 
	rice	Rice        
	cotn	Cotton      
	citr	Citrus      
	appl	ApplePears  
	stfr	StoneFruits 
	otnt	OthFrtNuts  
	prmd	PremGrapDryL
	prmi	PremGrapIrrg
	mltg	MultiGrape  
	past	PastureIrrig
	vege	Vegetables  
	othc	OthCrops    

	prim	Other primary products
	food	Food products
	wine	Wine

	othm	OtherManufac

	util	Utilities   
	cons	Construction
	trad	Trade       
	trns	Transport   
	coms	CommunicSrvc
	bank	BankFinIns  
	dwel	OwnerDwellng
	bsrv	BusSrvc     
	govt	GovDefEduHlt
	oths	OtherServces /;

set ii /
	shep	Sheep       
	othb	OthBroadAcre
	bctl	BeefCattle  
	dctl	DairyCattle 
	rice	Rice        
	cotn	Cotton      
	citr	Citrus      
	appl	ApplePears  
	stfr	StoneFruits 
	otnt	OthFrtNuts  
	prmd	PremGrapDryL
	prmi	PremGrapIrrg
	mltg	MultiGrape  
	past	PastureIrrig
	vege	Vegetables  
	othc	OthCrops    

	prim	Other primary products
	food	Food products
	wine	Wine

	othm	OtherManufac

	util	Utilities   
	cons	Construction
	trad	Trade       
	trns	Transport   
	coms	CommunicSrvc
	bank	BankFinIns  
	dwel	OwnerDwellng
	bsrv	BusSrvc     
	govt	GovDefEduHlt
	oths	OtherServces /;


set rr /	NSW1	NorthernNSW ,    
		NSW2	NorthWestNSW,    
		NSW3	MrmbidgeeNSW,    
		NSW4	MurrayNSW   ,    
		NSW5	FarWestNSW  ,    
		NSW0	RoNSW       
		VIC1	MalleeVIC   ,    
		VIC2	LoddonCmpVIC,    
		VIC3	GoulbournVIC,    
		VIC4	OvensMrryVIC,    
		VIC0	RoVIC       ,    
		QLD1	DarlDownsQLD
		QLD2	SouthWestQLD,    
		QLD0	RoQLD       ,    
		SA1	MurrayLndsSA,    
		SA0	Other South Australia,    
		WA	Wester Australia,    
		TAS	Tasmania
		NT	Northern Territory,    
		ACT     Australian Capital Territory/;    

$goto readdata

$label full

set rr /	NSW1	NorthernNSW ,    
		NSW2	NorthWestNSW,    
		NSW3	MrmbidgeeNSW,    
		NSW4	MurrayNSW   ,    
		NSW5	FarWestNSW  ,    
		NSW0	RoNSW       
		VIC1	MalleeVIC   ,    
		VIC2	LoddonCmpVIC,    
		VIC3	GoulbournVIC,    
		VIC4	OvensMrryVIC,    
		VIC0	RoVIC       ,    
		QLD1	DarlDownsQLD
		QLD2	SouthWestQLD,    
		QLD0	RoQLD       ,    
		SA1	MurrayLndsSA,    
		SA0	Other South Australia,    
		WA	Wester Australia,    
		TAS	Tasmania
		NT	Northern Territory,    
		ACT     Australian Capital Territory/;    

set ii /shep	Sheep       
	barl	Barley      
	whet	Wheat       
	othb	OthBroadAcre
	bctl	BeefCattle  
	dctl	DairyCattle 
	pigs	PigsPoultry 
	rice	Rice        
	cotn	Cotton      
	citr	Citrus      
	appl	ApplePears  
	stfr	StoneFruits 
	otnt	OthFrtNuts  
	prmd	PremGrapDryL
	prmi	PremGrapIrrg
	mltg	MultiGrape  
	cane	SugarCane   
	past	PastureIrrig
	vege	Vegetables  
	othc	OthCrops    
	agsr	AgricSrvces 
	fors	Forestry    
	fish	Fishing     
	mine	Mining      
	beef	BeefProds   
	meat	OthMeatProds
	dair	DairyProds  
	frut	FruitProc   
	vegp	VegetablProc
	flou	FlourCereals
	refn	SugarRef    
	seaf	SeaFood     
	wine	PremiumWine 
	ripl	BulkWine    
	othf	OthFoodPrd  
	wovn	FibreWoven  
	othm	OtherManufac
	drns	WaterDrains 
	util	Utilities   
	cons	Construction
	trad	Trade       
	trns	Transport   
	coms	CommunicSrvc
	bank	BankFinIns  
	dwel	OwnerDwellng
	bsrv	BusSrvc     
	govt	GovDefEduHlt
	oths	OtherServces /;

set cc /shep	Sheep       
	barl	Barley      
	whet	Wheat       
	othb	OthBroadAcre
	bctl	BeefCattle  
	dctl	DairyCattle 
	pigs	PigsPoultry 
	rice	Rice        
	cotn	Cotton      
	citr	Citrus      
	appl	ApplePears  
	stfr	StoneFruits 
	otnt	OthFrtNuts  
	prmd	PremGrapDryL
	prmi	PremGrapIrrg
	mltg	MultiGrape  
	cane	SugarCane   
	past	PastureIrrig
	vege	Vegetables  
	othc	OthCrops    
	agsr	AgricSrvces 
	fors	Forestry    
	fish	Fishing     
	mine	Mining      
	beef	BeefProds   
	meat	OthMeatProds
	dair	DairyProds  
	frut	FruitProc   
	vegp	VegetablProc
	flou	FlourCereals
	refn	SugarRef    
	seaf	SeaFood     
	wine	PremiumWine 
	ripl	BulkWine    
	othf	OthFoodPrd  
	wovn	FibreWoven  
	othm	OtherManufac
	drns	WaterDrains 
	util	Utilities   
	cons	Construction
	trad	Trade       
	trns	Transport   
	coms	CommunicSrvc
	bank	BankFinIns  
	dwel	OwnerDwellng
	bsrv	BusSrvc     
	govt	GovDefEduHlt
	oths	OtherServces /;


$label readdata

SET	user(*)	Industries and components of final demand
	c(*)	Commodities
	l(*)	Skills
	i(user)	Industries
	r(*)	Regions of use - production - origin
	s(*)	States;

$gdxin 'aggmdb.gdx'
$load user c=com i=ind l=occ r=regdst s=state

ALIAS (r,rx,rm), (rr,rrx,rrm), (cc,mmrg);

SET	fd(user)	Components of final demand /HOU, INV,GOV, EXP/,
	mrg(c)		Margins /trade, transport/,
	src		Sources /dom, imp/;

$goto %mapping%map

$label fullmap

set mapi(ii,i)	Mapping fom aggregate goods to database goods /
	shep.Sheep       
	barl.Barley      
	whet.Wheat       
	othb.OthBroadAcre
	bctl.BeefCattle  
	dctl.DairyCattle 
	pigs.PigsPoultry 
	rice.Rice        
	cotn.Cotton      
	citr.Citrus      
	appl.ApplePears  
	stfr.StoneFruits 
	otnt.OthFrtNuts  
	prmd.PremGrapDryL
	prmi.PremGrapIrrg
	mltg.MultiGrape  
	cane.SugarCane   
	past.PastureIrrig
	vege.Vegetables  
	othc.OthCrops    
	agsr.AgricSrvces 
	fors.Forestry    
	fish.Fishing     
	mine.Mining      
	beef.BeefProds   
	meat.OthMeatProds
	dair.DairyProds  
	frut.FruitProc   
	vegp.VegetablProc
	flou.FlourCereals
	refn.SugarRef    
	seaf.SeaFood     
	wine.PremiumWine 
	ripl.BulkWine    
	othf.OthFoodPrd  
	wovn.FibreWoven  
	othm.OtherManufac
	drns.WaterDrains 
	util.Utilities   
	cons.Construction
	trad.Trade       
	trns.Transport   
	coms.CommunicSrvc
	bank.BankFinIns  
	dwel.OwnerDwellng
	bsrv.BusSrvc     
	govt.GovDefEduHlt
	oths.OtherServces /;

set mapc(cc,c)	Mapping fom aggregate goods to database goods /
	shep.Sheep       
	barl.Barley      
	whet.Wheat       
	othb.OthBroadAcre
	bctl.BeefCattle  
	dctl.DairyCattle 
	pigs.PigsPoultry 
	rice.Rice        
	cotn.Cotton      
	citr.Citrus      
	appl.ApplePears  
	stfr.StoneFruits 
	otnt.OthFrtNuts  
	prmd.PremGrapDryL
	prmi.PremGrapIrrg
	mltg.MultiGrape  
	cane.SugarCane   
	past.PastureIrrig
	vege.Vegetables  
	othc.OthCrops    
	agsr.AgricSrvces 
	fors.Forestry    
	fish.Fishing     
	mine.Mining      
	beef.BeefProds   
	meat.OthMeatProds
	dair.DairyProds  
	frut.FruitProc   
	vegp.VegetablProc
	flou.FlourCereals
	refn.SugarRef    
	seaf.SeaFood     
	wine.PremiumWine 
	ripl.BulkWine    
	othf.OthFoodPrd  
	wovn.FibreWoven  
	othm.OtherManufac
	drns.WaterDrains 
	util.Utilities   
	cons.Construction
	trad.Trade       
	trns.Transport   
	coms.CommunicSrvc
	bank.BankFinIns  
	dwel.OwnerDwellng
	bsrv.BusSrvc     
	govt.GovDefEduHlt
	oths.OtherServces /;

set MAPR(rr,R) /
		NSW1.NorthernNSW ,    
		NSW2.NorthWestNSW,    
		NSW3.MrmbidgeeNSW,    
		NSW4.MurrayNSW   ,    
		NSW5.FarWestNSW  ,    
		NSW0.RoNSW       
		VIC1.MalleeVIC   ,    
		VIC2.LoddonCmpVIC,    
		VIC3.GoulbournVIC,    
		VIC4.OvensMrryVIC,    
		VIC0.RoVIC       ,    
		QLD1.DarlDownsQLD
		QLD2.SouthWestQLD,    
		QLD0.RoQLD       ,    
		SA1.MurrayLndsSA,    
		SA0.SA,    
		WA.WA,    
		TAS.TAS
		NT.NT,    
		ACT.ACT/;    

$goto aggregate

$label watermap

set mapi(ii,i)	Mapping fom aggregate goods to database goods /
	shep.Sheep       
	othb.OthBroadAcre
	bctl.BeefCattle  
	dctl.DairyCattle 
	rice.Rice        
	cotn.Cotton      
	citr.Citrus      
	appl.ApplePears  
	stfr.StoneFruits 
	otnt.OthFrtNuts  
	prmd.PremGrapDryL
	prmi.PremGrapIrrg
	mltg.MultiGrape  
	past.PastureIrrig
	vege.Vegetables  
	othc.OthCrops    
	prim.(	Barley
		Wheat
		PigsPoultry
		SugarCane
		AgricSrvces
		Forestry    
		Fishing     
		Mining),
	food.(
		BeefProds   
		OthMeatProds
		DairyProds  
		FruitProc   
		VegetablProc
		FlourCereals
		SugarRef    
		SeaFood    
		OthFoodPrd  ),
	wine.(	PremiumWine 
		BulkWine    )
	othm.(	FibreWoven  
		OtherManufac
		WaterDrains )
	util.Utilities   
	cons.Construction
	trad.Trade       
	trns.Transport   
	coms.CommunicSrvc
	bank.BankFinIns  
	dwel.OwnerDwellng
	bsrv.BusSrvc     
	govt.GovDefEduHlt
	oths.OtherServces /;

set mapc(cc,c)	Mapping fom aggregate goods to database goods /
	shep.Sheep       
	othb.OthBroadAcre
	bctl.BeefCattle  
	dctl.DairyCattle 
	rice.Rice        
	cotn.Cotton      
	citr.Citrus      
	appl.ApplePears  
	stfr.StoneFruits 
	otnt.OthFrtNuts  
	prmd.PremGrapDryL
	prmi.PremGrapIrrg
	mltg.MultiGrape  
	past.PastureIrrig
	vege.Vegetables  
	othc.OthCrops    
	prim.(	Barley
		Wheat
		PigsPoultry
		SugarCane
		AgricSrvces
		Forestry    
		Fishing     
		Mining),
	food.(
		BeefProds   
		OthMeatProds
		DairyProds  
		FruitProc   
		VegetablProc
		FlourCereals
		SugarRef    
		SeaFood    
		OthFoodPrd  ),
	wine.(	PremiumWine 
		BulkWine    )
	othm.(	FibreWoven  
		OtherManufac
		WaterDrains )
	util.Utilities   
	cons.Construction
	trad.Trade       
	trns.Transport   
	coms.CommunicSrvc
	bank.BankFinIns  
	dwel.OwnerDwellng
	bsrv.BusSrvc     
	govt.GovDefEduHlt
	oths.OtherServces /;

set MAPR(rr,R) /
		NSW1.NorthernNSW ,    
		NSW2.NorthWestNSW,    
		NSW3.MrmbidgeeNSW,    
		NSW4.MurrayNSW   ,    
		NSW5.FarWestNSW  ,    
		NSW0.RoNSW       
		VIC1.MalleeVIC   ,    
		VIC2.LoddonCmpVIC,    
		VIC3.GoulbournVIC,    
		VIC4.OvensMrryVIC,    
		VIC0.RoVIC       ,    
		QLD1.DarlDownsQLD
		QLD2.SouthWestQLD,    
		QLD0.RoQLD       ,    
		SA1.MurrayLndsSA,    
		SA0.SA,    
		WA.WA,    
		TAS.TAS
		NT.NT,    
		ACT.ACT/;    

$goto aggregate


$label tinymap

set mapi(ii,i)	Mapping fom aggregate goods to database goods /
	agri.(	Sheep       
		OthBroadAcre
		BeefCattle  
		DairyCattle 
		Rice        
		Cotton      
		Citrus      
		ApplePears  
		StoneFruits 
		OthFrtNuts  
		PremGrapDryL
		PremGrapIrrg
		MultiGrape  
		PastureIrrig
		Vegetables  
		OthCrops    
	    ),
	prim.(	Barley
		Wheat
		PigsPoultry
		SugarCane
		AgricSrvces
		Forestry    
		Fishing     
		Mining),
	food.(
		BeefProds   
		OthMeatProds
		DairyProds  
		FruitProc   
		VegetablProc
		FlourCereals
		SugarRef    
		SeaFood    
		OthFoodPrd
		PremiumWine 
		BulkWine    )

	othm.(	FibreWoven  
		OtherManufac
		WaterDrains 
		Utilities   )

	trad.Trade       
	trns.Transport   

	serv.(
		Construction
		CommunicSrvc
		BankFinIns  
		OwnerDwellng
		BusSrvc     
		GovDefEduHlt
		OtherServces ) /;

set mapc(cc,c)	Mapping fom aggregate goods to database goods /
	agri.(	Sheep       
		OthBroadAcre
		BeefCattle  
		DairyCattle 
		Rice        
		Cotton      
		Citrus      
		ApplePears  
		StoneFruits 
		OthFrtNuts  
		PremGrapDryL
		PremGrapIrrg
		MultiGrape  
		PastureIrrig
		Vegetables  
		OthCrops    
	    ),
	prim.(	Barley
		Wheat
		PigsPoultry
		SugarCane
		AgricSrvces
		Forestry    
		Fishing     
		Mining),
	food.(
		BeefProds   
		OthMeatProds
		DairyProds  
		FruitProc   
		VegetablProc
		FlourCereals
		SugarRef    
		SeaFood    
		OthFoodPrd
		PremiumWine 
		BulkWine    )

	othm.(	FibreWoven  
		OtherManufac
		WaterDrains 
		Utilities   )

	trad.Trade       
	trns.Transport   

	serv.(
		Construction
		CommunicSrvc
		BankFinIns  
		OwnerDwellng
		BusSrvc     
		GovDefEduHlt
		OtherServces ) /;

set MAPR(rr,R) /
		NSW1.NorthernNSW ,    
		NSW2.NorthWestNSW,    
		NSW3.MrmbidgeeNSW,    
		NSW4.MurrayNSW   ,    
		NSW5.FarWestNSW  ,    
		NSW0.RoNSW       
		VIC1.MalleeVIC   ,    
		VIC2.LoddonCmpVIC,    
		VIC3.GoulbournVIC,    
		VIC4.OvensMrryVIC,    
		VIC0.RoVIC       ,    
		QLD1.DarlDownsQLD
		QLD2.SouthWestQLD,    
		QLD0.RoQLD       ,    
		SA1.MurrayLndsSA,    
		SA0.SA,    
		WA.WA,    
		TAS.TAS
		NT.NT,    
		ACT.ACT/;    

$label aggregate

PARAMETER
	cap(i,r)		"Rentals to capital (48x20)",
	lab(i,l,r)		"Wage matrix (48x9x20)",
	lnd(i,r)		"Rentals to land (48x20)",
	ptx(i,r)		"Taxes on production (48x20)",
	use(c,src,user,r)	"Basic + margin flows (48x2x52x20)",
	invest(c,i,r)		"investment at purchasers prices (48x48x20)",
	dep(i)			"Depreciation rates adapted from MONASH model (48)",
	expelas(c)		"Export demand elasticity (48) (+)",
	feed0(i)		"FEED0(i (48))",
	make(c,i,r)		"MAKE matrix (48x48x20)",
        suppmar(c,r,r,r)	"Margins supplied by REGPRD on goods passing from (2x20x20x20)",

	armsigma(c)		"Armington from PDA (Jan 2002),remapped (48)",
	frisch(r)		"Frisch LES parameter= - (total/luxury (20))",
	sigma1prim(i)		"CES substitution, primary factors (48)",
	pop(r)			"Regional population June 2001 (20)",
	regstate(r,s)		"Maps regions to states (20x8)",
	sigmadomdom(c)		"Between-region Armington (48)",
	sigma1lab(i)		"CES substitution between skill types (48)",
	sigmamar(mrg)		"Elasticity of substitution between regions of margin production (2)",

	stocks(i,r)		"Domestic inventories (48x20)",

	trade(c,src,r,r)	"Sourcing matrix (48x2x20x20)",
	tradmar(c,src,mrg,r,r)	"Margins on trade matrix (48x2x2x20x20)",
	taxes(c,src,user,r)	"Taxes  (48x2x52x20))",

	usewater(i,r)		"Value of water used (48x20)",
	wateruse(i,r)		"Water used (16x12)",
	wat_elas(i)		"Water-saving responsiveness (48)",
	wrights(i,r)		"Water rights (16x12)";

$load cap=v1cap lab=v1lab lnd=v1lnd ptx=v1ptx invest use=basmar dep expelas feed0 make suppmar armsigma 
$load frisch sigma1prim pop regstate sigmadomdom sigma1lab sigmamar stocks 
$load tradmar trade taxes usewater wateruse=waterirg wat_elas wrights=waterirga 


parameter
 	cap_(ii,rr)		"Rentals to capital (48x20)",
	lab_(ii,l,rr)		"Wage matrix (48x9x20)",
	lnd_(ii,rr)		"Rentals to land (48x20)",
	ptx_(ii,rr)		"Taxes on production (48x20)",
	use_(cc,src,*,rr)	"Basic + margin flows (48x2x52x20)",
	invest_(cc,ii,rr)		"investment at purchasers prices (48x48x20)",
	dep_(ii)			"Depreciation rates adapted from MONASH model (48)",
	expelas_(cc)		"Export demand elasticity (48) (+)",
	feed0_(ii)		"FEED0(i (48))",
	make_(cc,ii,rr)		"MAKE matrix (48x48x20)",
        suppmar_(cc,rr,rr,rr)	"Margins supplied by REGPRD on goods passing from (2x20x20x20)",

	armsigma_(cc)		"Armington from PDA (Jan 2002),remapped (48)",
	frisch_(r)		"Frisch LES parameter= - (total/luxury (20))",
	sigma1prim_(ii)		"CES substitution, primary factors (48)",
	pop_(rr)		"Regional population June 2001 (20)",
	regstate_(rr,s)		"Maps regions to states (20x8)",
	sigmadomdom_(cc)	"Between-region Armington (48)",
	sigma1lab_(ii)		"CES substitution between skill types (48)",
	sigmamar_(cc)		"Elasticity of substitution between regions of margin production (2)",

	stocks_(ii,rr)		"Domestic inventories (48x20)",

	trade_(cc,src,rr,rr)	"Sourcing matrix (48x2x20x20)",
	tradmar_(cc,src,*,rr,rr) "Margins on trade matrix (48x2x2x20x20)",
	taxes_(cc,src,*,rr)	"Taxes  (48x2x52x20))",

	usewater_(ii,rr)	"Value of water used (48x20)",
	wateruse_(ii,rr)	"Water used (16x12)",
	wat_elas_(ii)		"Water-saving responsiveness (48)",

	wrights_(ii,rr)		"Water rights (16x12)";

cap_(ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), cap(i,r)));
lab_(ii,l,rr) = sum(mapr(rr,r), sum(mapi(ii,i), lab(i,l,r)));
lnd_(ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), lnd(i,r)));
ptx_(ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), ptx(i,r)));

use_(cc,src,fd,rr) = sum(mapr(rr,r), sum(mapc(cc,c), use(c,src,fd,r)));
use_(cc,src,ii,rr) = sum(mapr(rr,r), sum((i,c)$(mapi(ii,i) and mapc(cc,c)), use(c,src,i,r)));
invest_(cc,ii,rr) = sum(mapr(rr,r), sum((i,c)$(mapi(ii,i) and mapc(cc,c)), invest(c,i,r)));
dep_(ii) = sum(mapi(ii,i), dep(i));
feed0_(ii) = sum(mapi(ii,i), feed0(i));
make_(cc,ii,rr) = sum(mapr(rr,r), sum((i,c)$(mapi(ii,i) and mapc(cc,c)), make(c,i,r)));
suppmar_(cc,rrx,rrm,rr) = 
		sum((rm,r,rx)$(mapr(rrm,rm)*mapr(rrx,rx)*mapr(rr,r)),
		sum(mapc(cc,c), suppmar(c,rx,rm,r)));

stocks_(ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), stocks(i,r)));
trade_(cc,src,rr,rrm) = sum((r,rm)$(mapr(rr,r) and mapr(rrm,rm)),
	sum(mapc(cc,c), trade(c,src,r,rm)));
tradmar_(cc,src,mmrg,rr,rrm) = sum((r,rm)$(mapr(rr,r) and mapr(rrm,rm)),
	sum(mrg$mapc(mmrg,mrg), sum(mapc(cc,c), tradmar(c,src,mrg,r,rm))));

taxes_(cc,src,fd,rr) = sum(mapr(rr,r), sum(mapc(cc,c), taxes(c,src,fd,r)));
taxes_(cc,src,ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), sum(mapc(cc,c), taxes(c,src,i,r))));

usewater_(ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), usewater(i,r)));
wateruse_(ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), wateruse(i,r)));
wrights_(ii,rr) = sum(mapr(rr,r), sum(mapi(ii,i), wrights(i,r)));

expelas_(cc) = sum(mapc(cc,c), expelas(c)) / sum(mapc(cc,c),1);
armsigma_(cc) = sum(mapc(cc,c), armsigma(c)) / sum(mapc(cc,c),1);
sigma1prim_(ii) = sum(mapi(ii,i), sigma1prim(i)) / sum(mapi(ii,i),1);
sigmadomdom_(cc) = sum(mapc(cc,c), sigmadomdom(c)) / sum(mapc(cc,c),1);
sigma1lab_(ii) = sum(mapi(ii,i), sigma1lab(i)) / sum(mapi(ii,i),1);
sigmamar_(cc)$sum(mapc(cc,mrg),1)
	 = sum(mapc(cc,mrg), sigmamar(mrg)) / sum(mapc(cc,mrg),1);
wat_elas_(ii) = sum(mapi(ii,i), wat_elas(i)) / sum(mapi(ii,i),1);

set user_(*); user_(fd) = yes; user_(ii) = yes;

execute_unload 'aggr.gdx', user_=user, cc=com, ii=ind, l=occ, rr=regdst, s=state,
cap_=v1cap,lab_=v1lab,lnd_=v1lnd,ptx_=v1ptx,invest_=invest,use_=basmar,dep_=dep,
expelas_=expelas,feed0_=feed0,make_=make,suppmar_=suppmar,armsigma_=armsigma,
frisch,sigma1prim_=sigma1prim,pop,regstate,sigmadomdom_=sigmadomdom,
sigma1lab_=sigma1lab,sigmamar_=sigmamar,stocks_=stocks,
tradmar_=tradmar,trade_=trade,taxes_=taxes,usewater_=usewater,
wateruse_=waterirg,wat_elas_=wat_elas,wrights_=waterirga;

